package com.yjs.ppjokedemo.bean;

import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.DiffUtil;

import com.bumptech.glide.Glide;

import java.util.Objects;

public class TextProduct {

    private String name;
    private String caption;
    private String ivTou;

    public TextProduct(String name, String caption, String ivTou) {
        this.name = name;
        this.caption = caption;
        this.ivTou = ivTou;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCaption() {
        return caption;
    }

    public void setCaption(String caption) {
        this.caption = caption;
    }

    public String getIvTou() {
        return ivTou;
    }

    public void setIvTou(String ivTou) {
        this.ivTou = ivTou;
    }

    @Override
    public String toString() {
        return "TextProduct{" +
                "name='" + name + '\'' +
                ", caption='" + caption + '\'' +
                ", ivTou='" + ivTou + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TextProduct that = (TextProduct) o;
        return Objects.equals(name, that.name) && Objects.equals(caption, that.caption) && Objects.equals(ivTou, that.ivTou);
    }

    public static DiffUtil.ItemCallback<TextProduct> itemCallback = new DiffUtil.ItemCallback<TextProduct>() {
        @Override
        public boolean areItemsTheSame(@NonNull TextProduct oldItem, @NonNull TextProduct newItem) {
            return oldItem.getName().equals(newItem.getName());
        }

        @Override
        public boolean areContentsTheSame(@NonNull TextProduct oldItem, @NonNull TextProduct newItem) {
            return oldItem.equals(newItem);
        }
    };

    @BindingAdapter("app:loadImageText")
    public static void loadImageText(ImageView imageView, String ivTou){
        Glide.with(imageView.getContext())
                .load(ivTou)
                .circleCrop()
                .into(imageView);

    }
}
